package ms.unicorn.language.languagedef;

import org.eclipse.xtext.util.CancelIndicator;
import org.eclipse.xtext.xbase.XExpression;
import org.eclipse.xtext.xbase.interpreter.IEvaluationContext;
import org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter;

@SuppressWarnings("restriction")
public class XbaseUtil {
	public static IEvaluationContext context;
	public static XbaseInterpreter interpreter;
	
	@SuppressWarnings("unchecked")
	public static <T> T evaluate(XExpression exp, T defaultValue) {
		if (interpreter != null)
			return (T)interpreter.evaluate(exp, context, CancelIndicator.NullImpl).getResult();
		return defaultValue;
	}
}
